package com.dzm.thirdpart.interceptor;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 作者：Dzm
 * 时间：2024-09-18-15:32
 * 功能：
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        String name = (String) session.getAttribute("name");
        if(!StringUtils.isEmpty(name)) {
            //用户已经登录无需在登陆，跳回首页
            response.sendRedirect("http://portal.daxigua.com");
            return false;
        }

        return true;
    }
}
